package redis;

import java.util.Set;

import org.junit.Test;

import redis.clients.jedis.Jedis;

public class TestSet {
	static Jedis jedis = null;

    static {
        jedis = new Jedis("192.168.79.131", 6379);//redis服务器地址与端口号
        jedis.auth("211125");    }
    
    // 测试Java做为客户端连接redis
    public static void main(String[] args) {
    	System.out.println("服务启动..."+jedis.ping());
    	jedis.flushDB();
    }
    
    // 7.5.5 操作集合
    @Test
    public void saddTest() {
    	Long result = jedis.sadd("databases", "redis", "mongodb", "neo4j");
    	System.out.println(result);
    }
    
    @Test
    public void scardTest() {
    	Long num = jedis.scard("databases");
    	System.out.println(num);
    }
    
    @Test
    public void smembersTest() {
    	Set<String> databases = jedis.smembers("databases");
    	System.out.println(databases);
    }
    
    @Test
    public void sismemberTest() {
    	Boolean result = jedis.sismember("databases","mysql");
    	System.out.println(result);
    }
    
    @Test
    public void sremTest() {
    	Long result = jedis.srem("databases","redis");
    	System.out.println(result);
    }
}
